package com.qijian.common.utils.poi.handler;

import com.google.common.base.Strings;
import com.qijian.common.utils.poi.ExcelHandlerAdapter;
import org.apache.commons.lang3.StringUtils;

public class YearMonthCastDate implements ExcelHandlerAdapter {
    @Override
    public Object format(Object value, String[] args) {
        if (value instanceof String) {
            String v = (String) value;
            if (v.contains("年") && v.contains("月")) {
                String year = StringUtils.substringBefore((String) value, "年").trim();
                String month = StringUtils.substringBetween((String) value, "年", "月").trim();
                return year + '-' + Strings.padStart(month, 2, '0');
            }
        }
        return value;
    }
}
